fix: notify() generates iv_nonce and a fresh session_id per call#522
Open
cconstab wants to merge 4 commits into
Open
fix: notify() generates iv_nonce and a fresh session_id per call#522cconstab wants to merge 4 commits into
cconstab wants to merge 4 commits into
Conversation
notify() crashed when the AtKey had no iv_nonce ('nonce must be bytes-like'),
forcing callers to set metadata.iv_nonce manually. It also used a signature
default session_id=str(uuid.uuid4()), which is evaluated once at import, so every
notify() without an explicit id reused the same one and the server deduped the
duplicates.
Generate the AES nonce inside notify() when unset (and store it on the key's
metadata so it travels with the notification), and default session_id to None,
generating a fresh UUID per call.
Adds network-free unit tests for both behaviours.
There was a problem hiding this comment.
Pull request overview
This PR fixes two long-standing correctness issues in AtClient.notify() by ensuring encrypted notifications always have the required AES-CTR nonce and by preventing reuse of a single import-time session_id. It also adds network-free regression tests covering both behaviors.
Changes:
- Change
notify()to defaultsession_idtoNoneand mint a fresh UUID per call when not provided. - Ensure
notify()generates and setsmetadata.iv_noncewhen it is missing, preventing AES-CTR crashes. - Add
test/notify_test.pyto validate thesession_iddefault and nonce generation without requiring network connections.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| at_client/atclient.py | Fix notify() session ID default behavior and generate/store an AES-CTR nonce when missing. |
| test/notify_test.py | Add regression tests ensuring session_id is not an import-time UUID and iv_nonce is generated. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…yptionUtil import in test Addresses review: AES-CTR nonce must not be reused across notify() calls on a reused AtKey — generate a fresh nonce every call instead of only when unset. Test now also asserts two calls on the same key produce different nonces. Import EncryptionUtil via the package (from at_client.util) to match the rest of the suite.
Member
Author
|
Thanks @copilot-pull-request-reviewer — both addressed:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
notify()had two defects, both inat_client/atclient.py:at_key.metadata.iv_nonceand passed itstraight to
aes_encrypt_from_base64; if the caller hadn't set it, AES-CTR raisednonce must be bytes-like. Callers had to setmetadata.iv_noncemanually.session_id=str(uuid.uuid4())isevaluated once at import, so every
notify()without an explicit id reused the sameid for the process lifetime. The atServer dedups by notification id, so duplicate /
rapid notifications were silently dropped.
Fix: generate the nonce inside
notify()when unset (and store it on the key'smetadata so it travels with the notification for the receiver to decrypt), and default
session_idtoNone, minting a fresh UUID per call.Tests:
test/notify_test.py— network-free:session_iddefault isNone(regression against the import-time UUID)notify()setsiv_noncewhen the key has none (mocked network)Found while building a production integration on atsdk; both were reproducible in
isolation.